<template>
	<view class="box">
		<view class="box-list" v-if="list.length>0">
			<u-swipe-action>
				<u-swipe-action-item :options="options" v-for="item in list" :key="item.id"
					style="margin-bottom: 20rpx;" @click="click(item)">
					<view class="swiper-box">
						<view class="box-left">
							<view>事项名称 : {{item.name}}</view>
							<view style="margin-top: 10rpx;">时间 : {{item.dateTime}}</view>
							<view style="margin-top: 10rpx;">闹钟频率 : 每{{item.frequency}}小时提醒</view>
							<view style="margin-top: 10rpx;">描述 : {{item.descContent}}</view>
						</view>
						<view class="box-right">
							<image src="@/static/image/clock.png" mode=""></image>
							<u-button type="primary" size="mini" style="width: 120rpx;" v-if="item.recordsId"
								text="记录体温" :disabled="item.status!==1" color="#54b6ab" @click="toNav(item.recordsId)"></u-button>
							<u-button type="primary" size="mini" style="width: 120rpx;" v-else text="其他事件"
								color="#54b6ab"></u-button>
						</view>
					</view>
				</u-swipe-action-item>
			</u-swipe-action>
		</view>

		<view v-else>
			<u-empty
			        mode="list"
			        icon="http://cdn.uviewui.com/uview/empty/list.png"
			>
			</u-empty>
		</view>

		<view class="box-footer">
			<u-button type="primary" style="height: 100rpx;" text="添加代办事项" @click="show = true"
				color="#54b6ab"></u-button>
		</view>


		<u-popup :show="show" mode="center" @close="close" :closeOnClickOverlay="false" bgColor="transparent">
			<view class="dialog">
				<view class="dialog-title">
					<text>添加事项</text>
					<u-icon name="close" @click="show = false"></u-icon>
				</view>
				<view class="dialog-form">
					<u--form labelPosition="left" :labelStyle="{color:'#666',fontSize:'18rpx'}" :model="addObj"
						ref="uForm">
						<u-form-item label="事项名称:" labelWidth="80">
							<u--input border="none" v-model="addObj.name" placeholder="输入事项名称"></u--input>
						</u-form-item>
						<u-form-item label="日期时间:" labelWidth="80">
							<uni-datetime-picker type="datetime" v-model="addObj.dateTime" start="1990-01-01"
								end="2990-01-01" @change="changeDate" />
						</u-form-item>
						<u-form-item label="闹钟频率:" labelWidth="80" @click="showClock = true">
							<view @click="showClock = true">
								<u--input border="none" v-model="addObj.frequency" disabledColor="#fff" disabled
									placeholder="请选择"></u--input>
							</view>
						</u-form-item>
						<u-form-item label="描述:" labelWidth="80">
							<u--input border="none" v-model="addObj.descContent" placeholder="输入内容"></u--input>
						</u-form-item>

						<u-button type="primary" shape="circle" color="#54b6ab" text="确 定" @click="submit"></u-button>
					</u--form>
				</view>
			</view>

		</u-popup>


		<u-picker :closeOnClickOverlay="true" :show="showClock" :columns="clockColumns" @confirm="confirm"
			@cancel="showClock = false"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				show: false,
				showClock: false,
				clockColumns: [
					['每两小时提醒', '每三小时提醒', '每四小时提醒']
				],
				list: [],
				addObj: {
					name: null,
					dateTime: null,
					frequency: null,
					descContent: null,
					recordsId: null
				}
			};
		},
		onShow() {
			this.findAll()
		},
		methods: {
			toNav(id){
				uni.setStorageSync('setRecordId',id)
				uni.switchTab({
					url:'/pages/nav'
				})
			},
			async findAll() {
				const {
					data
				} = await uni.$http.post('/patient-wait-do/findAll')
				if (data.code === 200) {
					this.list = data.data
				}
			},
			async submit() {
				if (this.addObj.frequency == '每两小时提醒') {
					this.addObj.frequency = 2
				}
				if (this.addObj.frequency == '每三小时提醒') {
					this.addObj.frequency = 3
				}
				if (this.addObj.frequency == '每四小时提醒') {
					this.addObj.frequency = 4
				}
				const {
					data
				} = await uni.$http.post('/patient-wait-do/save', this.addObj)
				if (data.code === 200) {
					this.findAll()
					this.show = false
					uni.showToast({
						icon: 'none',
						title: data.message
					})
				}

			},
			//点击删除
			async click(item) {
				const{data} =await uni.$http.post('/patient-wait-do/deleteById?id='+item.id)
				if(data.code===200){
					this.findAll()
					uni.showToast({
						icon:'none',
						title:data.message
					})
				}
			},
			//关闭弹窗
			close() {
				this.show = false
			},
			//选择日期
			changeDate(e) {
				this.addObj.dateTime = e;
			},
			//选择时间
			changeTime(e) {
				this.form.time = e;
			},
			//选择频次
			confirm(val) {
				this.addObj.frequency = val.value[0]
				this.showClock = false
			}
		}
	}
</script>

<style lang="scss">
	.box {
		position: relative;
		width: 100%;
		height: 100%;
		background-color: #f2f2f2;
		overflow: auto;

		.box-list {
			width: 100%;
			height: calc(100% - 120rpx);
			padding: 20rpx;
			overflow: auto;
			box-sizing: border-box;

			.swiper-box {
				width: 100%;
				border: 2rpx solid #54b6ab;
				box-sizing: border-box;
				padding: 20rpx;
				display: flex;
				align-items: stretch;
				justify-content: space-between;

				.box-left {
					width: 70%;
				}

				.box-right {
					width: 30%;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: space-around;

					image {
						width: 80rpx;
						height: 80rpx;
					}
				}
			}
		}

		.box-footer {
			z-index: 999;
			position: absolute;
			bottom: 0;
			width: 100%;
			height: 100rpx;
		}

		.dialog {
			width: 80vw;
			margin: 0 auto;
			// padding: 20rpx;
			border-radius: 20rpx;
			background-color: #fff;
			box-sizing: border-box;

			.dialog-title {
				width: 100%;
				display: flex;
				align-items: center;
				padding: 20rpx;
				box-sizing: border-box;
				justify-content: space-between;
				border-bottom: 1rpx solid #ccc;
			}

			.dialog-form {
				width: 100%;
				padding: 20rpx;
				box-sizing: border-box;

				/deep/.u-input__content__field-wrapper__field {
					font-size: 18rpx !important;
				}
			}
		}
	}
</style>